//
//  StatusTableCellTopView.swift
//  SinaWeibo
//
//  Created by 胡阳 on 16/6/1.
//  Copyright © 2016年 young4ever. All rights reserved.
//

import UIKit

class StatusTableCellTopView: UIView {
    
    var status : Status? {
    
        didSet{
            // 用户名
            nameLabel.text = status?.user?.name
            // 时间
            timeLabel.text = status?.created_at
            // 来源
            sourceLabel.text = status?.source
            // 头像
            avatorImage.sd_setImageWithURL(status?.user?.imageURL)
            // 验证图片
            verifyImage.image = status?.user?.verifyImage
            // vip等级图片
            vipImage.image = status?.user?.vipImage
        }
    }
    

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupSubviews()
    }
    
    
    private func setupSubviews()
    {
        //1.添加子控件
        addSubview(avatorImage)
        addSubview(verifyImage)
        addSubview(nameLabel)
        addSubview(vipImage)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        
        //2.布局子控件
        avatorImage.xmg_AlignInner(type: XMG_AlignType.TopLeft, referView: self, size: CGSizeMake(50, 50) ,offset: CGPointMake(10, 10))
        verifyImage.xmg_AlignInner(type: XMG_AlignType.BottomRight, referView: avatorImage, size: CGSize(width: 14, height: 14), offset: CGPoint(x: 5, y: 5))
        nameLabel.xmg_AlignHorizontal(type: XMG_AlignType.TopRight, referView: avatorImage, size: nil, offset: CGPoint(x: 10, y: 0))
        vipImage.xmg_AlignHorizontal(type: XMG_AlignType.TopRight, referView: nameLabel, size: CGSize(width: 14, height: 14), offset: CGPoint(x: 10, y: 0))
        timeLabel.xmg_AlignHorizontal(type: XMG_AlignType.BottomRight, referView: avatorImage, size: nil, offset: CGPoint(x: 10, y: 0))
        sourceLabel.xmg_AlignHorizontal(type: XMG_AlignType.BottomRight, referView: timeLabel, size: nil, offset: CGPoint(x: 10, y: 0))
    }
    
    // MARK:- 懒加载子控件
    /**
     *  头像
     */
    private lazy var avatorImage: UIImageView = {
        
        let img = UIImageView(image: UIImage(named: "avatar_default"))
        return img
    }()
    
    /**
     *  认证图标
     */
    private lazy var verifyImage: UIImageView = {
        
        let img = UIImageView(image: UIImage(named: "avatar_enterprise_vip"))
        return img
    }()
    
    /**
     *  昵称
     */
    private lazy var nameLabel: UILabel = UILabel.fastCreateLabel(UIColor.orangeColor(), fontSize: 15)
    
    /**
     *  会员图标
     */
    private lazy var vipImage: UIImageView = {
        
        let img = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
        return img
    }()
    
    /**
     *  时间
     */
    private lazy var timeLabel: UILabel = UILabel.fastCreateLabel(UIColor.lightGrayColor(), fontSize: 14)
    
    /**
     *  来源
     */
    private lazy var sourceLabel: UILabel = UILabel.fastCreateLabel(UIColor.lightGrayColor(), fontSize: 14)
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
